using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using Newtonsoft.Json;

public class SensitiveInfoScanner
{
    private List<Regex> _patterns;

    public SensitiveInfoScanner()
    {
        LoadPatternsFromFile("patterns.json");
    }

    private void LoadPatternsFromFile(string filePath)
    {
        var jsonContent = File.ReadAllText(filePath);
        var patternStrings = JsonConvert.DeserializeObject<List<string>>(jsonContent);
        _patterns = new List<Regex>();

        foreach (var pattern in patternStrings)
        {
            _patterns.Add(new Regex(pattern));
        }
    }

    public List<(string FileName, int LineNumber, string Match)> ScanFile(string filePath)
    {
        var results = new List<(string, int, string)>();
        var lines = File.ReadAllLines(filePath);

        for (int i = 0; i < lines.Length; i++)
        {
            foreach (var pattern in _patterns)
            {
                var matches = pattern.Matches(lines[i]);
                foreach (Match match in matches)
                {
                    results.Add((filePath, i + 1, match.Value));
                }
            }
        }

        return results;
    }
} 